package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.model.BaseCategory1;
import com.atguigu.gmall.product.model.BaseCategory2;
import com.atguigu.gmall.product.model.BaseCategory3;
import com.atguigu.gmall.product.service.BaseCategory1Service;
import com.atguigu.gmall.product.service.BaseCategory2Service;
import com.atguigu.gmall.product.service.BaseCategory3Service;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class BaseCategoryController {


    @Autowired
    private BaseCategory1Service baseCategory1Service;

    @Autowired
    private BaseCategory2Service baseCategory2Service;

    @Autowired
    private BaseCategory3Service baseCategory3Service;


    /**
     * 查询所有一级分类列表
     *
     * @return
     */
    @GetMapping("/getCategory1")
    public Result getCategory1List() {
        List<BaseCategory1> list = baseCategory1Service.getCategory1List();
        return Result.ok(list);
    }

    /**
     * 根据一级分类ID查询该分类下二级分类列表
     * @param category1Id
     * @return
     */
    @GetMapping("/getCategory2/{category1Id}")
    public Result getCategory2List(@PathVariable("category1Id") Long category1Id){
        List<BaseCategory2> list = baseCategory2Service.getCategory2List(category1Id);
        return Result.ok(list);
    }


    /**
     * 根据二级分类ID查询该分类下三级分类列表
     * @param category2Id
     * @return
     */
    @ApiOperation("根据二级分类ID查询该分类下三级分类列表")
    @GetMapping("/getCategory3/{category2Id}")
    public Result getCategory3List(@PathVariable("category2Id") Long category2Id){
        List<BaseCategory3> list = baseCategory3Service.getCategory3List(category2Id);
        return Result.ok(list);
    }
}